package com.llyb.controller;

import cn.hutool.core.date.DateUtil;
import com.llyb.inter.ChatMemoryAssistant;
import dev.langchain4j.model.chat.ChatModel;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class ChatMemoryController {

    @Autowired
    private ChatModel chatModel;

    @Resource(name = "chatMessageWindowChatMemory")
    private ChatMemoryAssistant chatMemoryAssistant;


    // http://localhost:9008/chatmemory/chat1
    @GetMapping("/chatmemory/chat1")
    public String  chatMemory() {

        String answer1 = chatModel.chat("你好，我叫llyb");
        System.out.println("第一次回答"+answer1);

        String answer2 = chatModel.chat("我叫什么？");
        System.out.println("第二次回答"+answer2);
        return "success : "+ DateUtil.now()+"<br> \n\n answer01: "+answer1+"<br> \n\n answer02: "+answer2;
    }


    @GetMapping("/chatmemory/chat2")
    public String  chatMemory2() {

        String answer1 = chatMemoryAssistant.chatWithChatMemory(1L,"你好，我叫java");
        System.out.println("第一次回答"+answer1);

        String answer2 = chatMemoryAssistant.chatWithChatMemory(1L,"我叫什么？");
        System.out.println("第二次回答"+answer2);

        String answer3 = chatMemoryAssistant.chatWithChatMemory(3L,"你好，我叫C++");
        System.out.println("第三次回答"+answer1);

        String answer4 = chatMemoryAssistant.chatWithChatMemory(3L,"我叫什么？");
        System.out.println("第四次回答"+answer2);
        return "success : "+ DateUtil.now()+"<br> \n\n answer01: "+answer1+"<br> \n\n answer02: "+answer2+
                "success : "+ DateUtil.now()+"<br> \n\n answer03: "+answer3+"<br> \n\n answer04: "+answer4;
    }

    @GetMapping("/chatmemory/chat3")
    public String  chatMemory3() {

        String answer1 = chatMemoryAssistant.chatWithChatMemory(1L,"你好，我叫php");
        System.out.println("第一次回答"+answer1);

        String answer2 = chatMemoryAssistant.chatWithChatMemory(1L,"我叫什么？");
        System.out.println("第二次回答"+answer2);

        String answer3 = chatMemoryAssistant.chatWithChatMemory(3L,"你好，我叫go");
        System.out.println("第三次回答"+answer1);

        String answer4 = chatMemoryAssistant.chatWithChatMemory(3L,"我叫什么？");
        System.out.println("第四次回答"+answer2);
        return "success : "+ DateUtil.now()+"<br> \n\n answer01: "+answer1+"<br> \n\n answer02: "+answer2+
                "success : "+ DateUtil.now()+"<br> \n\n answer03: "+answer3+"<br> \n\n answer04: "+answer4;
    }



}
